package poker;

public class check {
	card[] karty;
	String Score;

	check(final card[] karty) {
		this.karty = karty;
		Score = "";
		sprawdzenie();
	}

	public final void sprawdzenie() {
		String s = "AKQJ198765432";
		int[] k = new int[13];
		for (int i = 0; i < 5; i++) {
			k[s.indexOf(karty[i].figura.charAt(0))]++;
		}
		int sum = 0;
		for (int temp : k) {
			if (temp > 0) {
				sum++;
			}
		}
		switch (sum) {
		case 5:
			if (pokolei(k)) {
				if (kolor()) {
					Score += "1";
				} else {
					Score += "5";
				}
			} else {
				if (kolor()) {
					Score += "4";
				} else {
					Score += "9";
				}
			}
			break;
		case 4:
			Score += "8";
			break;
		case 3:
			if (k[high(k)] == 2) {
				Score += "7";
			} else {
				if (k[downHigh(k)] == 2) {
					Score += "7";
				} else {
					Score += "6";
				}
			}

			break;
		case 2:
			if(k[highNumber(k)]==3) {
				Score += "3";
			} else {
				Score += "2";
			}
			break;
		default:
			break;
		}
		Score += ".";
		for (int i = 0; i < sum; i++) {
			if(highNumber(k)<9) {
				Score +="0";
			}
			Score +=Integer.toString(highNumber(k)+ 1);
			if (i + 1 != sum) {
				Score += ".";
			}
			k[highNumber(k)] = 0;

		}

	}

	final boolean pokolei(final int[] tab) {
		int s = 0;
		for (int temp : tab) {
			if (temp > 0) {
				s++;
			} else
				return s == 5;
		}
		return false;
	}

	public final int high(final int[] tab) {
		int i;
		for (i = 0; i < 13; i++) {
			if (tab[i] > 0) {
				break;
			}
		}
		return i;
	}

	public final int highNumber(final int[] tab) {
		int i, index = 0, temp = 0;
		for (i = 0; i < 13; i++) {
			if (tab[i] > temp) {
				temp = tab[i];
				index = i;
			}
		}
		return index;
	}

	public final int downHigh(final int[] tab) {
		int i;
		for (i = 12; i >= 0; i--) {
			if (tab[i] > 0) {
				break;
			}
		}
		return i;
	}

	public final boolean kolor() {
		return karty[0].kolor == karty[1].kolor
				&& karty[0].kolor == karty[2].kolor
				&& karty[0].kolor == karty[3].kolor
				&& karty[0].kolor == karty[4].kolor;
	}

}
